<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/1
 * Time: 下午6:46
 */
class Base extends MY_Admin_Controller
{
    public function index()
    {
        $this->load->model('special/model_special','special');
        $specialInfo = $this->special->getAllLists();

        $data = array(
            'specialInfo' => $specialInfo
        );

        $this->load->view('admin/special/base/index',$data);
    }


    public function create()
    {
        $sid = $this->uri->segment(4);

        $this->load->model('special/model_special','special');
        $specialInfo = $this->special->getById($sid);

        $data = array(
            'specialInfo'  => $specialInfo,
        );

        $this->load->view('admin/special/base/create',$data);
    }

    /*
    * 竞拍资料编辑后保存
    *
    * */
    public function save()
    {

        $sid = (int)$this->input->get_post('sid');

        $data = array(
            'name'           =>     trim($this->input->get_post('name')),
            'link'           =>     trim($this->input->get_post('link')),
            'view_num'       =>     (int)$this->input->get_post('view_num'),
            'content'        =>     $this->input->get_post('content'),
            'share_num'      =>     (int)$this->input->get_post('share_num'),
            'status'         =>     (int)$this->input->get_post('status'),
        );

        //更新
        $this->load->model('special/model_special','special');
        $this->special->save($data, $sid);

        $this->load->helper('url');
        redirect(url('admin').'special/base/index');
    }


    /**
     * 删除道具
     */
    public function delete()
    {
        $response = array('code' => '0', 'msg' => '操作成功');

        do {
            $sid = (int)$this->input->get_post('sid');

            if (!$sid)
            {
                $response = error(160001);
                break;
            }

            $this->load->model('special/model_special','special');
            $res = $this->special->delete(array('sid' => $sid));

            if (!$res)
            {
                $response = error(10080);
                break;
            }
        }while (false);


        $this->json_output($response);
    }
}